<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>药品基本信息</title>
</head>
<body>
	<div id="medcineManage" class="easyui-tabs"
		style="width: 100%; height: 100%;">
		<div title="药品信息" data-options="iconCls:'icon-add'"
			style="display: none;">
			<div id="medcineToolbar" style="padding-left: 5px">
				<input id="searchMedcineName" class="easyui-searchbox"
					data-options="
		      				prompt:'请输入药品名',width:200
		      			">
				<span style="padding-left: 10px; font-size: 14px">药品类别</span><span
					style="padding-left: 5px"> <select id="medcineDetailTypeSearch" class="easyui-combobox"
					data-options="width:120,url:'getAllMedcineType',method:'get',panelHeight:'auto',valueField:'medcinetypeId',textField:'medcineTypeName'"></select>
				</span> <span style="padding-left: 10px; font-size: 14px">药品单位</span> <span
					style="padding-left: 5px"> <select id="medcineDetailCompanySearch" class="easyui-combobox"
					data-options="width:120,url:'getAllMedcineCompany',method:'get',panelHeight:'auto',valueField:'medcinecompanyId',textField:'medcinecompanyName'"></select>
					
				</span> <a id="medcineDetailSearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查找</a>
				<span style="padding-left: 10px"> <a id="allMedcineDetail_btn"
					class="easyui-linkbutton" data-options="iconCls:'icon-tip'">全部药品</a>
				</span>
			</div>
			<table id="medcineDetailGrid" style="width: 100%; height: 80%"
				class="easyui-datagrid"
				data-options="rownumbers:true,fitColumns:true,url:'getAllMedcineDetails',method:'get',toolbar:'#medcineToolbar',pagination:true,title:'药品信息',singleSelect:true">
				<thead>
					<tr>
						<th data-options="field:'medcineId'"></th>
						<th data-options="field:'medcineName',width:100,align:'center'">名称</th>
						<th data-options="field:'medcineImage',width:100">图片</th>
						<th data-options="field:'medcinePrice',width:50,align:'center'">价格</th>
						<th data-options="field:'medcineBaozhiqi',width:70,align:'center'">保质期(天)</th>
						<th data-options="field:'medcineEffect',width:100">处方药</th>
						<th data-options="field:'medcineTypeName',width:100">药品类</th>
						<th data-options="field:'medcineCompanyName',width:100">药品单位</th>
						<th data-options="field:'medcineNote',width:100">药品备注</th>
					</tr>
				</thead>
			</table>
			<div style="width: 100%; height: 20%;">
				<div style="width: 100%; height: 20%"></div>
				<div style="height: 80%; width: 100%; text-align: center">
					<a id="addMedcineDetail" class="easyui-linkbutton"
						data-options="iconCls:'icon-add'">新增药品</a> <span
						style="padding-left: 10px"> <a id="deleteMedcineDetail"
						class="easyui-linkbutton" data-options="iconCls:'icon-no'">删除药品</a>
					</span> <span style="padding-left: 10px"> <a
						id="editMedcineDetail" class="easyui-linkbutton"
						data-options="iconCls:'icon-edit'">修改药品</a>
					</span>
				</div>
			</div>
		</div>
		<div title="药品类别" data-options="iconCls:'icon-add'"
			style="overflow: auto; display: none;">
			<div id="medcineTypeToolbar" style="padding-left:5px">
				<a id="addMedcineType" data-options="iconCls:'icon-add'" class="easyui-linkbutton">新增类别</a>
				
			</div>
			<table id="medcineTypeGrid" class="easyui-datagrid" data-options="toolbar:'#medcineTypeToolbar',singleSelect:true,url:'getAllMedcineTypeMap',method:'get',title:'药品分类',rownumbers:true,pagination:true,fitColumns:true" style="width:100%;height:100%">
				<thead>
					<tr>
						<th data-options="width:100,field:'medcinetypeId',align:'center'">药品编号</th>
						<th data-options="width:100,field:'medcineTypeName',align:'center'">药品类名称</th>
						<th data-options="width:250,field:'medcinetypeEffect'">药品类效用</th>
						<th data-options="width:300,field:'medcinetypeNote'">药品类备注</th>
					</tr>
				</thead>
			</table>
			
			</div>
		<div title="药品单位" data-options="iconCls:'icon-add'"
			style=" display: none;">
			<div id="medcineCompanyToolbar" style="padding-left:5px">
				<a id="addMedcineCompany" class="easyui-linkbutton" data-options="iconCls:'icon-add'">新增单位</a>
				
			</div>
			<table id="medcineCompanyGrid" class="easyui-datagrid" data-options="toolbar:'#medcineCompanyToolbar',singleSelect:true,url:'getAllMedcineCompanyMap',method:'get',title:'药品单位',rownumbers:true,pagination:true,fitColumns:true,fit:true" >
				<thead>
					<tr>
						<th data-options="width:100,field:'medcinecompanyId',align:'center'">药品单位编号</th>
						<th data-options="width:100,field:'medcinecompanyName',align:'center'">药品单位名称</th>
					</tr>
				</thead>
			</table>
			</div>
	</div>
	<!-- 新增药品类-->
	<div id="addMedcineTypeWin" class="easyui-window"
		data-options="title:'新增药品类',
					width:500,
					height:230,
					iconCls:'icon-add',
					closed:true,
					modal:true,
					border:'thick',
					draggable:false,
					resizable:false
					">
		<!-- 新增药品类表单 -->
		<form id="addMedcineTypeForm" method="post"
			action="addMedcineType">
			<div style="padding: 20px" class="easyui-panel"
				data-options="fit:true">
				<table style="width: 100%; height: 150px">
					<tr>
						<td>药品类名 <span style="padding-left: 33px"><input
								style="width: 100px" name="medcineTypeName"
								class="easyui-validatebox" data-options="required:true"></span>
						</td>
						<td style="padding-left: 10px">类别效用<span
							style="padding-left: 33px">
							<input style="width:100px" name="medcineTypeEffect" class="easyui-textbox">
						</span>
						</td>
					</tr>
					<tr>
						<td>类别备注 <span style="padding-left: 33px"><input
								style="width: 100px" name="medcineTypeNote"
								class="easyui-textbox" ></span>
						</td>
						<td style="text-align: right"><a id="addMedcineTypeYes"
							class="easyui-linkbutton" data-options="iconCls:'icon-add'">确定</a>
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<!-- 新增药品单位表单 -->
	<div id="addMedcineCompanyWin" class="easyui-window" 
		data-options="title:'新增药品单位',
					width:500,
					height:230,
					iconCls:'icon-add',
					closed:true,
					modal:true,
					border:'thick',
					draggable:false,
					resizable:false
					">
			<form id="addMedcineCompanyForm" action="addMedcineCompany" method="post">
				<div style="padding: 20px" class="easyui-panel"
				data-options="fit:true">
				<table style="width: 100%; height: 150px">
					<tr>
						<td>药单位名 <span style="padding-left: 33px"><input
								style="width: 100px" name="medcineCompanyName"
								class="easyui-validatebox" data-options="required:true"></span>
						</td>
						<td style="text-align: right"><a id="addMedcineCompanyYes"
							class="easyui-linkbutton" data-options="iconCls:'icon-add'">确定</a>
						</td>
					</tr>
				</table>
			</div>
			</form>
	
	</div>
	<!-- 新增药品 -->
	<div id="addMedcineDetailWin" class="easyui-window"
		data-options="title:'新增药品',
					width:600,
					height:400,
					iconCls:'icon-add',
					closed:true,
					modal:true,
					border:'thick',
					draggable:false,
					resizable:false
					">
		<!-- 新增药品详情表单 -->
		<form id="addMedcineDetailForm" method="post"
			action="addMedcineDetail">
			<div style="padding: 20px" class="easyui-panel"
				data-options="fit:true">
				<table style="width: 100%; height: 320px">
					<tr>
						<td>药品名称 <span style="padding-left: 33px"><input
								style="width: 100px" name="medcineName"
								class="easyui-validatebox" data-options="required:true"></span>
						</td>
						<td style="padding-left: 10px">药品类别<span
							style="padding-left: 33px"><select name="medcineType"
								class="easyui-combobox"
								data-options="method:'get',url:'getAllMedcineType',panelHeight:'auto',valueField:'medcinetypeId',textField:'medcineTypeName',width:150,value:'1'"></select>
						</span>
						</td>
					</tr>
					<tr>
						<td>药品价格<span style="padding-left: 40px"><input
								name="medcinePrice" class="easyui-numberbox" min="0.01"
								max="1000000" precision="2"
								data-options="prompt:'请输入价格',width:100" required="true">
						</span>
						</td>
						<td style="padding-left: 10px">药品单位<span
							style="padding-left: 36px"><select name="medcineCompany"
								class="easyui-combobox"
								data-options="method:'get',url:'getAllMedcineCompany',panelHeight:'auto',valueField:'medcinecompanyId',textField:'medcinecompanyName',width:150,value:'1'"></select>
						</span>
						</td>
					</tr>
					<tr>
						<td>药品保质期(天)<span style="padding-left: 7px"><input
								name="medcineBaoZhiQi" class="easyui-numberbox" min="1"
								max="10000" data-options="width:100" required="true"> </span>
						</td>
						<td style="padding-left: 10px">药品备注<span
							style="padding-left: 36px"><input name="medcineNote"
								class="easyui-textbox" data-options="width:200,prompt:'片剂'">
						</span>
						</td>

					</tr>
					<tr>
						<td>处方药 <span style="padding-left: 50px"><select
								name="medcineEffect" class="easyui-combobox"
								data-options="width:100,panelHeight:'auto'">
									<option value="处方药" selected="selected">处方药</option>
									<option value="非处方药">非处方药</option>
							</select> </span>
						</td>
						<td style="padding-left: 10px">
							<!-- 图片上传 --> 图片 <span style="padding-left: 55px"><input
								type="file" name="medcineImage"></span>
						</td>
					</tr>
					<tr>
						<td></td>
						<td style="text-align: right"><a id="addMedcineYes"
							class="easyui-linkbutton" data-options="iconCls:'icon-add'">确定</a>
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<div id="updateMedcineDetailWin" class="easyui-window"
		data-options="title:'修改药品',
					width:600,
					height:400,
					iconCls:'icon-edit',
					closed:true,
					modal:true,
					border:'thick',
					draggable:false,
					resizable:false">
		<!-- 修改药品详情表单 -->
		<form id="editMedcineDetailForm" method="post"
			action="editMedcineDetail">
			<div style="padding: 20px" class="easyui-panel" id="editMedcineDetailPanel"
				data-options="fit:true">
				<input name="medcineId" id="editMedcineId" style="display:none" type="text">
				<table style="width: 100%; height: 320px">
					<tr>
						<td>药品名称 <span style="padding-left: 33px"><input
								id="editMedcineName"
								style="width: 100px" name="medcineName"
								class="easyui-textbox"></span>
						</td>
						<td style="padding-left: 10px">药品类别<span
							style="padding-left: 33px">
							<input id="editMedcineType1" class="easyui-textbox" style="width:50px">
							<select name="medcineType"
								class="easyui-combobox"
								data-options="method:'get',url:'getAllMedcineType',panelHeight:'auto',valueField:'medcinetypeId',textField:'medcineTypeName',width:150"></select>
						</span>
						</td>
					</tr>
					<tr>
						<td>药品价格<span style="padding-left: 40px"><input
								id="editMedcinePrice"
								name="medcinePrice" class="easyui-numberbox" min="0.01"
								max="1000000" precision="2"
								data-options="prompt:'请输入价格',width:100" required="true">
						</span>
						</td>
						<td style="padding-left: 10px">药品单位<span
							style="padding-left: 33px">
							<input class="easyui-textbox" style="width:50px" id="editMedcineCompany1">
							<select name="medcineCompany"
								class="easyui-combobox"
								data-options="method:'get',url:'getAllMedcineCompany',panelHeight:'auto',valueField:'medcinecompanyId',textField:'medcinecompanyName',width:150"></select>
						</span>
						</td>
					</tr>
					<tr>
						<td>药品保质期(天)<span style="padding-left: 7px"><input
								id="editMedcineBaoZhiQi"
								name="medcineBaoZhiQi" class="easyui-numberbox" min="1"
								max="10000" data-options="width:100" required="true"> </span>
						</td>
						<td style="padding-left: 10px">药品备注<span
							style="padding-left: 36px"><input name="medcineNote"
								id="editMedcineNote"
								class="easyui-textbox" data-options="width:210,prompt:'片剂'">
						</span>
						</td>

					</tr>
					<tr>
						<td>处方药 <span style="padding-left: 50px"><select
								id="editMedcineEffect"
								name="medcineEffect" class="easyui-combobox"
								data-options="width:100,panelHeight:'auto'">
									<option value="处方药" >处方药</option>
									<option value="非处方药">非处方药</option>
							</select> </span>
						</td>
						<td style="padding-left: 10px">
							<!-- 图片上传 --> 图片 <span style="padding-left: 55px"><input
								id="editMedcineImage"
								type="file" name="medcineImage"></span>
						</td>
					</tr>
					<tr>
						<td></td>
						<td style="padding-left:250px"><a id="editMedcineYes"
							class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<script>
		$(function() {
			//添加药品表单
			$("#addMedcineDetailForm").form({
				onSubmit : function() {
					var isValid = $(this).form('validate');
					if (!isValid) {
						console.log("提交失败");
					}
					return isValid;
				},
				success : function() {
					$("#medcineDetailGrid").datagrid('reload');
					$("#addMedcineDetailForm").form('clear');
					$("#addMedcineDetailWin").window('close');
					$.messager.alert("提示", "添加成功");
				}
			});
			//修改药品表单
			$("#editMedcineDetailForm").form({
				onSubmit : function() {
					var isValid = $(this).form('validate');
					if (!isValid) {
						console.log("修改失败");
					}
					return isValid;
				},
				success : function() {
					$("#medcineDetailGrid").datagrid('reload');
					$("#editMedcineDetailForm").form('clear');
					$("#updateMedcineDetailWin").window('close');
					$.messager.alert("提示", "修改成功");
				}
			});
			//添加药品详情
			$("#addMedcineDetail").linkbutton({
				onClick : function() {
					console.log(123);
					$("#addMedcineDetailWin").window('open');
				}
			});
			//添加药品
			$("#addMedcineYes").linkbutton({
				onClick : function() {
					console.log("addMedcineYes按钮触发");
					$("#addMedcineDetailForm").submit();
				}
			});
			//修改药品详情
			$("#editMedcineDetail").linkbutton({
				onClick : function() {
					$("#editMedcineDetailPanel").panel('refresh');
					var row = $("#medcineDetailGrid").datagrid('getSelected');
					if (row !=null) {
						console.log("row.medcineId="+row.medcineId);
						$("#editMedcineId").val(row.medcineId);
						console.log("editMedcineId"+$("#editMedcineId").val());
						//console.log("222"+$("#editMedcineId").attr("value"));
						$("#editMedcineName").textbox('setValue',row.medcineName);
						$("#editMedcineType1").textbox('setValue',row.medcineTypeName);
						$("#editMedcinePrice").numberbox('setValue',row.medcinePrice);
						$("#editMedcineCompany1").textbox('setValue',row.medcineCompanyName);
						$("#editMedcineBaoZhiQi").numberbox('setValue',row.medcineBaozhiqi);
						$("#editMedcineNote").textbox('setValue',row.medcineNote);
						console.log(row.medcineEffect);
						$("#editMedcineEffect").combobox('select',row.medcineEffect);
						//$("#editMedcineImage").val(row.medcineImage);
						$("#updateMedcineDetailWin").window('open');
					}else{
						//console.log("medcineId为空");
						$.messager.alert('提示','请选择要修改的行！');
					}
				}
			});
			//删除药品
			$("#deleteMedcineDetail").linkbutton({
				onClick : function(){
					var row = $("#medcineDetailGrid").datagrid('getSelected');
					console.log(typeof(medcineId));
					if(row.medcineId!=null){
						$.messager.confirm('提示','您确定要删除吗？',function(r){
							if(r){
								console.log("ddd"+row.medcineId);
								$.get('deleteMedcineDetail?medcineId='+row.medcineId,function(){
									$("#medcineDetailGrid").datagrid('reload');
									$.messager.alert('提示','删除成功');
								});
							}
						});
					}else{
						$.messager.alert('提示','请先选择一行');
					}
				}
			});
			//按条件查询药品详情
			$("#medcineDetailSearch").linkbutton({
				onClick : function(){
					var medcineTypeId = $("#medcineDetailTypeSearch").combobox('getValue');
					var medcineCompanyId = $("#medcineDetailCompanySearch").combobox('getValue');
					console.log("medcineTypeId="+medcineTypeId+"---medcineCompanyId="+medcineCompanyId);
					$("#medcineDetailGrid").datagrid('reload','searchSomeMedcineDetail?medcineTypeId='+medcineTypeId+'&medcineCompanyId='+medcineCompanyId);
					
				}
			});
			$("#editMedcineYes").linkbutton({
				onClick : function(){
				$("#editMedcineDetailForm").form('submit');
				}
			});
			//新增药品类表单
			$("#addMedcineTypeForm").form({
				onSubmit : function(){
					var isValidate = $(this).form('validate');
					if(!isValidate){
						console.log('提交失败');
					}
					return isValidate;
				},
				success : function(){
					$("#medcineTypeGrid").datagrid('reload');
					$("#addMedcineTypeForm").form('clear');
					$("#addMedcineTypeWin").window('close');
					$.messager.alert('提示','新增成功!');
				}
			});
			$("#addMedcineTypeYes").linkbutton({
				onClick : function(){
					console.log("addMedcineTypeYes按钮触发");
					$("#addMedcineTypeForm").form('submit');
				}
			});
			//新增药品类别
			$("#addMedcineType").linkbutton({
				onClick : function(){
					$("#addMedcineTypeWin").window('open');
				}
			});
			$("#addMedcineCompanyForm").form({
				onSubmit : function(){
					var isValid = $(this).form('validate');
					if(!isValid){
						console.log("提交失败");
					}
					return isValid;
				},
				success : function(){
					$("#medcineCompanyGrid").datagrid('reload');
					$("#addMedcineCompanyForm").form('clear');
					$("#addMedcineCompanyWin").window('close');
					$.messager.alert('提示','添加成功');
				}
			});
			//新增药品单位
			$("#addMedcineCompany").linkbutton({
				onClick : function(){
					$("#addMedcineCompanyWin").window('open');
				}
			});
			$("#addMedcineCompanyYes").linkbutton({
				onClick : function(){
					$("#addMedcineCompanyForm").form('submit');
				}
			});
			//全部药品
			$("#allMedcineDetail_btn").linkbutton({
				onClick:function(){
					$("#medcineDetailGrid").datagrid("load",'getAllMedcineDetails');
				}
			});
		});
		
	</script>
</body>
</html>